﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Flame.Dlr;
using System.Text.RegularExpressions;

namespace Flame.Reflection
{
    public class PythonIntellisense : AIntellisense
    {

        IntellisenseParsing _regex, _regexM;
        public PythonIntellisense(IExecutable pycompiler) : base(pycompiler)
        {
            _regex = IntellisenseParsing.RegexBuilder(@"", @"\.", @"[a-zA-Z0-9_]");
            _regexM = IntellisenseParsing.RegexBuilder(@"", @"\.", @"[a-zA-Z0-9_]", @"\([^\)]*");
        }

        public IEnumerable<string> GetList(string s)
        {
            IronPython.Runtime.List d = _compiler.Execute("dir(" + s + ")").Data as IronPython.Runtime.List;
           return  from x in d select x.ToString();
        }


        protected override IntellisenseParsing IntellisenseParsing_Method { get { return _regexM; } }
        protected override IntellisenseParsing IntellisenseParsing_Type { get { return _regex; } }



        public IEnumerable<IntellisenseItem> GetIntellisenseItemList(string s)
        {


            return null;

        }


        protected override Type InstanceTypeFromName(string word)
        {
            return (Type)_compiler.Execute("(" + word + ").GetType()").Data;
        }

        protected override Type ClassTypeFromName(string word)
        {
            return (Type)_compiler.Execute("clr.GetClrType(" + word + ")").Data;
        }

        protected override string[] ClassTypeFromName_More(string word)
        {
            return GetList(word).ToArray();
        }


       /* public void GetMatchResults(string text, out string svalue, out string spartialvalue)
        {
            Match m = _regex.Match(text);
            svalue = m.Groups[ValueString].Value;
            spartialvalue = m.Groups[PartialValueString].Value;
        }*/

        protected override string[] Split(string word)
        {
           return word.Split('.');
        }
        protected override string Clean(string word)
        {
            return word.TrimEnd('.');
        }
    }
}
